/*
* File: som_liear_regressor.h
* @Brief: the functions about linear regressor in SOM.
* @Author: Mr.Charley(Chinese name: Chenglin Jia).
* @Version: 1.0
* @Date: 2024/7/22
*/

#ifndef SOM_LINEAR_REGRESSOR_H
#define SOM_LINEAR_REGRESSOR_H

// The header file in this file.
#include "som_base.h"
#include "som_regularizer.h"
#include "som_linear_solver.h"

// The struct definetion of linear regressor in SOM.
struct Som_Linear_Regressor_
{
	Som_Regularizer *regularizer;
	Som_Linear_Solver som_linear_solver;
	CvMat* x;
};

typedef struct Som_Linear_Regressor_ Som_Linear_Regressor;


// The declaration of function in linear regressor in SOM.
/************************************************************************/
/*
 * @brief create the linear regressors object.
 * @param[in] som_regularization_type: The type of the regularization.
 * @param[in] lamda: The coefficient of regularize.
 * @param[in] regularize_last_row: No lamda for bias.
 * @param[in] som_linear_solver: the linear solver.
 * @param[in] x: The matrix x (Optional)
 * @return the new linear regressor object.
 */
 /************************************************************************/
SOM_EXPORT Som_Linear_Regressor* som_linear_regressor_new(Som_Regularization_Type regularization_type, float lamda,
	bool regularize_last_row, Som_Linear_Solver som_linear_solver, CvMat* x);

/************************************************************************/
/*
 * @brief Delete a linear regressors object.
 * @param[in] linear_regressor: linear regressors to delete.
 */
 /************************************************************************/
SOM_EXPORT void som_linear_regressor_delete(Som_Linear_Regressor* som_linear_regressor);

/************************************************************************/
/*
 * @brief Learn a predictor from given data and labels.
 * @param[in&out] linear_regressor: the object of linear regressor.
 * @param[in] data: Training data matrix, one example per row.
 * @param[in] labels: Labels corresponding to the training data.
 */
 /************************************************************************/
SOM_EXPORT void som_linear_regressor_learn(Som_Linear_Regressor* linear_regressor, const CvMat* data, const CvMat* labels);

/************************************************************************/
/*
 * @brief Predicts the regressed value for given sample.
 * @param[in] values: One data point as a row vector.
 * @return Return the predicted value.
 */
 /************************************************************************/
SOM_EXPORT CvMat* som_linear_regressor_predict(const CvMat* value, const Som_Linear_Regressor* linearregressor);

/************************************************************************/
/*
 * @brief Write the object Som_Linear_Regressor into the file.
 * @param[in] fp: The pointer of FILE to the file want to write in.
 * @param[in] som_linear_regressor: The object Som_Linear_Regressor want to write.
 * @return Return void.
 */
 /************************************************************************/
SOM_EXPORT void write_som_linear_regressor_into_file(FILE* fp, const Som_Linear_Regressor* som_linear_regressor);

/************************************************************************/
/*
 * @brief Read the object Som_Linear_Regressor from file given.
 * @param[in] fp: The pointer of FILE to the file want to read from.
 * @param[in&out] som_linear_regressor: The object Som_Linear_Regressor.
 * @return Return void.
 */
 /************************************************************************/
SOM_EXPORT void read_som_linear_regressor_from_file(FILE* fp, Som_Linear_Regressor* som_linear_regressor[]);

#endif // !SOM_LINEAR_REGRESSOR_H
